﻿using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
using XCWechat.Dtos;
using XCWechat.Entities.Clients;
using XCWechat.Repositories;

namespace XCWechat.Services.Clients
{
    [Dependency(ServiceLifetime.Transient)]
    public class ClientInfoService : CrudAppService<ClientInfo,                       //模型
                                                  ClientInfoDto,                    //结果出参Dto
                                                  Guid,                            //主键【删除入参】
                                                  PagedAndSortedResultRequestDto, //查询入参Dto
                                                  ClientInfoCreateDto,              //新增入参Dto
                                                  ClientInfoUpdateDto>,             //更新入参Dto
                                                  IClientInfoService
    {
        public IClientInfoRepository clientInfoRepository { get; set; }
        public IObjectMapper mapper { get; set; }

        public ClientInfoService(IRepository<ClientInfo, Guid> repository) : base(repository)
        {
        }

        /// <summary>
        /// 更新appToken
        /// </summary>
        /// <param name="appTokenUpdateDto"></param>
        /// <returns></returns>
        [RemoteService(false)]
        public async Task<string> UpdateAppToken(AppTokenUpdateDto appTokenUpdateDto)
        {
            ClientInfo clientInfo = mapper.Map<AppTokenUpdateDto, ClientInfo>(appTokenUpdateDto);
            ClientInfo result = await clientInfoRepository.UpdateAsync(clientInfo);
            string resultMsg = "";
            if(result != null)
            {
                resultMsg = "更新appToken成功！";
            }
            return resultMsg;
        }
    }
}
